<?php

namespace App\Events\V1;

use Jenssegers\Agent\Agent;
use Illuminate\Support\Facades\Auth;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

/**
 * 登录事件类
 *
 * Class AdminLoginEvent
 * @package App\Events\V1
 */
class AdminLoginEvent extends BaseEvent
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $user;
    public $agent;
    public $req;
    public $rsp;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(Agent $agent, $req = [], $rsp = [])
    {
        $this->user = $this->getAuthUser();
        $this->agent = $agent;
        $this->req = $req;
        $this->rsp = $rsp;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return array|\Illuminate\Broadcasting\Channel
     */
    public function broadcastOn()
    {
        return new PrivateChannel('channel-name');
    }

    /**
     * 获取已认证用户
     *
     * @return \Illuminate\Contracts\Auth\Authenticatable|null
     */
    protected function getAuthUser()
    {
        return Auth::user();
    }
}
